<?php
namespace Apps\BoxMall\Model;

use Think\Model;

class MallGoodsModel extends \BaseModel {

	public function load($id = "") {
		$data = $this->find($id);
		if (!$data) {
			return false;
		}
		$data['imgs'] = json_decode($data['imgs'], ture) ? $data['imgs'] : "{}";
		$data['property'] = json_decode($data['property'], ture) ? $data['property'] : "{}";
		$data['imglist'] = array_values($data['imglist'] = json_decode($data['imgs'], ture));
		$data['propertyArray'] = json_decode($data['property'], ture);
		//spec
		$model = BoxModel("mall_goods_spec");
		$goods_spec = array();
		$data['goods_spec_array'] = $model->get(array('goods_id' => $data['id']));
		if (is_array($data['goods_spec_array'])) {
			foreach ($data['goods_spec_array'] as $key => $value) {
				$k = urlencode($value['spec_1'] . "_" . $value['spec_2'] . "_" . $value['spec_3']);
				$goods_spec[$k] = $value;
			}
		}
		$data['default_img'] = $data['imglist']['0']['file_url'];

		$data['goods_spec'] = urldecode(json_encode($goods_spec));
		//dump($data['imglist']);
		return $data;
	}

}
